<?php
/**
 * @政策类
 * 1、政策列表
 * 2、政策详情
 * 
 */
namespace app\policy\controller;
use app\common\controller\HomeCommon;
use think\Cache;

class Index extends HomeCommon
{
	public function __construct(){
		
		parent::__construct();
		
	
	}
	
	
    /**
     * 获得政策列表
     */
    public function get_policy(){
    	
    	
    	$where="  a.status=1  ";
    	
    	
    	
    	$field="policy_name,accept_time,content,about_files,files,create_time,identification";
    	$obj=db('policy a');
    	
    	
    	/***关键字***/
    	$keywords=request()->param('keywords','','trim');
    	if(!empty($keywords)){
    		$where.=" and a.policy_name like '%$keywords%' ";
    	}
    	/***行业***/
    	$industry_id=request()->param('industry_id',0,'intval');
    	if(!empty($industry_id)){
    		$obj=$obj->join('policy_industry b','a.id=b.policy_id');
    		$where.=" and b.status=1 and b.industry_id=$industry_id";
    	}
    	
    	/***产业链***/
    	$chain_id=request()->param('chain_id',0,'intval');
    	if(!empty($chain_id)){
    		$obj=$obj->join('policy_chain c','a.id=c.policy_id');
    		$where.=" and c.status=1 and c.chain_id=$chain_id";
    	}
    	
    	/***城市***/
    	$city_id=request()->param('city_id',0,'intval');
    	if(!empty($city_id)){
    		$where.=" and (a.province_id=$city_id or a.city_id=$city_id or a.area_id=$city_id ) ";
    	}
    	
    	
    	
    	
    	
    	$listobj=$obj->field($field)->where($where)->paginate();
    	
    	
    	return json(['errcode'=>'0','msg'=>lang('Get success'),'data'=>$listobj]);
    	
    	
    }
    /**
     * 获得政策详情
     */
    public function get_policy_info(){
    	
    	
    	$where['status']=['=',1];
    	
    	
    	$identification=request()->param('identification','','trim');
    	
    	
    	if(!empty($identification)){
    		$where['identification']=['=', $identification];
    		
    		
    		$cache=new Cache();
    		$result=$cache->get('policy_'.$identification);
    		
    		
    		if($result){
    			$info=unserialize($result);
    		}else{
    			$field="policy_name,accept_time,content,about_files,files,create_time,identification";
    			$model= model('Commondata');
    			
    			$info=$model->get_detail('policy',$field,$where);
    			$cache->set('policy_'.$identification, serialize($info),3600);
    		}
    		
    		
    		return json(['errcode'=>'0','msg'=>lang('Get success'),'data'=>$info]);
    		
    		
    	}else{
    		return json(['errcode'=>'-1','msg'=>lang('param error'),'data'=>[]]);
    	}
    	
    	
    	
    	
    	
    }
}
